package com.cloud.adrian.novel.search.manager.feign;

import com.cloud.adrian.novel.book.dto.resp.BookEsRespDto;
import com.cloud.adrian.novel.book.feign.BookFeign;
import com.cloud.adrian.novel.common.constant.ErrorCodeEnum;
import com.cloud.adrian.novel.common.resp.RestResp;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @Author: xiangguiliang
 * @version: 1.0
 * @since: 2024/05/26
 */
@Component
@AllArgsConstructor
public class BookFeignManager {
    private final BookFeign bookFeign;

    public List<BookEsRespDto> listEsBooks(Long maxId) {
        RestResp<List<BookEsRespDto>> listRestResp = bookFeign.listNextEsBooks(maxId);
        if (Objects.equals(ErrorCodeEnum.OK.getCode(), listRestResp.getCode())) {
            return listRestResp.getData();
        }
        return new ArrayList<>(0);
    }


    public BookEsRespDto selectBookById(Long bookId) {
        RestResp<BookEsRespDto> bookEs = bookFeign.selectBookById(bookId);
        if (Objects.equals(ErrorCodeEnum.OK.getCode(), bookEs.getCode())) {
            return bookEs.getData();
        }
        return BookEsRespDto.builder().build();
    }
}
